跳到主要内容

Enhanced for loop in JAVA

Enhanced for loop:

for (String element : array) {
// rest of code handling current element
}

Traditional for loop equivalent:

for (int i=0; i < array.length; i++) {
String element = array[i];
// rest of code handling current element
}